"""
RedFlag-TC000033   快慢速功能检查
使用快慢速拍摄视频后保存查看
"""
__author__ = "ldm"

import sys
import os
# 获取当前脚本所在目录.py
current_dir = os.path.dirname(os.path.abspath(__file__))
# 获取上级目录.air
parent_dir = os.path.dirname(current_dir)
# 获取上级目录air
grandparent_dir = os.path.dirname(parent_dir)
# 获取和air目录平级的conf、testcase目录路径
conf_dir = os.path.join(grandparent_dir, 'conf')
testcase_dir = os.path.join(grandparent_dir, 'testcase')
# 将conf、testcase目录添加到sys.path
sys.path.append(conf_dir)
sys.path.append(testcase_dir)

from PageFunction import CameraVideoShooter
from elements import *
from device_elements import *
auto_setup(__file__)

shooter = CameraVideoShooter()

log("------------------------------快慢速功能检查场景-----------------------------")
"""
进入拍摄页
点击快慢速
选择极快
断言是否选择成功
拍摄3S的视频

选择快
断言是否选择成功
拍摄3S的视频

选择标准
断言是否选择成功
拍摄3S的视频

选择慢
断言是否选择成功
拍摄3S的视频

选择极慢
断言是否选择成功
拍摄视频等待进入装饰页
点击保存

进入相册
进入所有照片
获取视频时长
断言
"""

shooter.enter_photograph()
shooter.click_element(shooting_page_60_seconds)
shooter.click_element(shooting_page_fast_slow_speed)
shooter.click_element(fast_slow_speed_extremely_fast)
shooter.assert_image_exists(r"tpl1745983194407.png", "断言失败,目标图片并未出现")
shooter.multiple_dense_clicks(shooting_button, 2, 3)

shooter.click_element(fast_slow_speed_fast)
shooter.assert_image_exists(r"tpl1745985852650.png", "断言失败,目标图片并未出现")
shooter.multiple_dense_clicks(shooting_button, 2, 3)

shooter.click_element(fast_slow_speed_standard)
shooter.assert_image_exists(r"tpl1745985860827.png", "断言失败,目标图片并未出现", timeout=5)
shooter.multiple_dense_clicks(shooting_button, 2, 3)

shooter.click_element(fast_slow_speed_slow)
shooter.assert_image_exists(r"tpl1745985870113.png", "断言失败,目标图片并未出现",(-0.136, 0.325), (1224, 2700))
shooter.multiple_dense_clicks(shooting_button, 2, 3)

shooter.click_element(fast_slow_speed_extremely_slow)
shooter.assert_image_exists(r"tpl1745985885407.png", "断言失败,目标图片并未出现", (-0.279, 0.321), (1224, 2700))
shooter.click_element(shooting_button)
shooter.wait_for_element_appearance(decoration_page_release_video, 30)

shooter.click_element(decoration_page_save)
shooter.wait_for_image_appearance(r"tpl1745995629517.png", (0.011, -0.007), (1224, 2700), 200)

# 关闭应用
stop_app(UGC_package_name)


# 获取手机品牌
phone_model = shooter.get_phone_model()
#判断调用方法
if phone_model:
    if "huawei" in phone_model.lower() or "华为" in phone_model:
        shooter.click_element(Comes_photo_album_huawei)
        shooter.click_element(Comes_photo_album_all_photos[1].child("com.huawei.photos:id/album_cover_image"))
        time_text = shooter.get_element_text(Comes_photo_album_time[0].offspring("com.huawei.photos:id/item_video_duration"))
        shooter.assert_texts_equal(time_text, "01:00", "断言失败,获取的视频时间与预期时间不一致")
        # 关闭应用
        stop_app("com.huawei.photos")
    elif "vivo" in phone_model.lower():
        shooter.click_element(Comes_photo_album_vivo)
        shooter.click_element(Comes_photo_album_all_photos_vivo)
        shooter.click_element(Comes_photo_album_frist_video_vivo.child())
        shooter.click_element(Comes_photo_album_set_up_vivo)
        time_text = shooter.get_element_text(Comes_photo_album_time_vivo)
        shooter.assert_texts_equal(time_text, "01:00", "断言失败,获取的视频时间与预期时间不一致")
        # 关闭应用
        stop_app("com.vivo.gallery")

    else:
        print(f"不支持的手机品牌: {phone_model}")
else:
    print("无法获取手机型号信息，跳过断言操作")



